﻿/////////////////////////////////////////////////
//文件名:GetData
//描  述:
//创建者:刘凡平(Iveely Liu)
//邮  箱:945222889@qq.com
//组  织:Iveely
//年  份:2012/5/22 9:55:45
///////////////////////////////////////////////


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IveelySE.BigData.Common;
using System.Net;

namespace IveelySE.BigData.MasterNode
{
    /// <summary>
    /// 远程数据类
    /// </summary>
    public class RemoteData
    {

        public static PObject dealWith(byte[] msg)
        {
            //建立发送对象
            PObject obj = (PObject)Common.Serialize.Byte2Obj(msg);
            //发送给子节点
            Common.Communication.Transfer.Client sendData = new Common.Communication.Transfer.Client(Program.storeList.ChoseNode(obj).IP,Program.Config.MasterReadPort);
            //发送到子节点服务               
            PObject result =(PObject) sendData.ConnectToServer(obj);
            return result;
        }

        /// <summary>
        /// 操作监听
        /// </summary>
        /// <returns></returns>
        public PObject Listen()
        {
            //字节接收容器
            byte[] msg = new byte[10240];
            //简历服务端
            Common.Communication.Transfer.Server userServer = new Common.Communication.Transfer.Server(Program.Config.IP, Program.Config.UserReadPort);
            //持续
            while (true)
            {
                //监听
                userServer.Listen(ref msg,dealWith);
              
            }
        }
    }
}
